package com.leyou.item.service.Impl;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import com.leyou.item.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> queryCateListById(Long pid) {

        Category category = new Category();
        category.setParentId(pid);
        return categoryMapper.select(category);
    }

    @Override
    public List<Category> queryByBrandById(Long bid) {
        return categoryMapper.queryByBrandId(bid);
    }

    public List<String> queryNamesByIds(List<Long> ids){
        List<Category> categories = categoryMapper.selectByIdList(ids);
       return categories.stream().map(category -> category.getName()).collect(Collectors.toList());
    }
}
